/**
 * KMP模板题，要求输出特征向量，以及可重叠匹配的每一个位置
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using Real = double;
using vi = vector<int>;
using pii = pair<int, int>;

template<typename IT = const char *>
void calcNext(IT begin, int n, vector<int> & next) {
    next.assign(n, 0);
    for(int i=1;i<n;++i){
        int k = next[i - 1];
        while(k > 0 and *(begin + i) != *(begin + k)){
            k = next[k - 1];
        }
        next[i] = (*(begin + i) == *(begin + k)) ? k + 1 : 0;
    }
    return;
}

template<typename IT = const char *>
void calcKMPNext(IT begin, int n, vector<int> & next) {
    next.assign(n + 1, 0); 
    int k = -1, i = 0;
    next[0] = -1;
    while(i < n){
        while(k >= 0 and *(begin + i) != *(begin + k)) k = next[k];
        ++i, ++k;
        if(i == n) break;
        next[i] = *(begin + i) == *(begin + k) ? next[k] : k;
    }
    next[n] = k;
    return;
}

template<typename IT = const char *>
int KMPCount(IT t, int tn, IT p, int pn, const vector<int> & next, vector<int> & pos){
    assert(pn + 1 == next.size());
    pos.clear();
    if(tn < pn) return 0;
    int tp = 0, pp = 0, ret = 0;
    while(tp < tn){
        if(-1 == pp or *(t + tp) == *(p + pp)) ++tp, ++pp;
        else pp = next[pp];
        if(pp == pn){
            ret += 1; pp = next[pn];
            pos.emplace_back(tp - pn);
        }
    }
    return ret;
}

string T, P;

void proc(){
    vi next, kmp, pos;
    int tn = T.length(), pn = P.length();
    calcNext(P.begin(), pn, next);
    calcKMPNext(P.begin(), pn, kmp);
    KMPCount(T.begin(), tn, P.begin(), pn, kmp, pos);
    for(auto i : pos) cout << i + 1 << "\n";
    for(auto i : next) cout << i << " ";
    cout << "\n";
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    // cin >> nofkase;
    while(nofkase--){
        cin >> T >> P;
        proc();
    }
    return 0;
}